<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: maliangcheng
  Date: 2020/8/13
  Time: 14:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="head.jsp"%>
<html>
<head>
    <title>self</title>
    <link rel="stylesheet" href="/resource/layui/css/layui.css">
</head>
<body>

<div class="row clearfix">
    <div class="col-md-12 column">
        <table class="layui-table" lay-data="{align:'center',height:330, url:'', id:'idTest'}">
            <thead>
            <tr>
                <th lay-data="{field:'employeesId', width:150, sort: true, fixed: true}">ID</th>
                <th lay-data="{field:'name', width:150}">姓名</th>
                <th lay-data="{field:'employeesGender', width:150, sort: true}">性别</th>
                <th lay-data="{field:'employeesContactPhone', width:150}">联系方式</th>
                <th lay-data="{field:'employeesContactAdd', width:160}">住址</th>
                <th lay-data="{field:'password', width:150, sort: true}">密码</th>
                <th lay-data="{field:'departmentId', width:150, sort: true}">部门编号</th>
                <th lay-data="{field:'departmentName', width:150, sort: true}">部门名称</th>
                <th lay-data="{field:'departmentContactPhone', width:150, sort: true}">部门联系电话</th>
                <th lay-data="{fixed: 'right', align:'center', toolbar: '#bar'}"></th>
            </tr>
            </thead>
            <tbody>
                <c:forEach var="employees" items="${list}">
                <tr>
                    <td>${employees.employeesId}</td>
                    <td>${employees.name}</td>
                    <td>${employees.employeesGender}</td>
                    <td>${employees.employeesContactPhone}</td>
                    <td>${employees.employeesContactAdd}</td>
                    <td>${employees.password}</td>
                    <td>${employees.departmentId}</td>
                    <td>${employees.departmentName}</td>
                    <td>${employees.departmentContactPhone}</td>
                </tr>
                    <script type="text/html" id="bar">
                        <a class="layui-btn layui-btn-xs" href="${pageContext.request.contextPath}/employees/toUpdateEmployees?name=${employees.name}">编辑</a>
                    </script>
                </c:forEach>
            </tbody>
        </table>
    </div>
</div>
<script src="/resource/layui/layui.js" charset="utf-8"></script>
<script src="../js/self.js"></script>
<script>
    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
            console.log(obj)
        });
        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.alert('编辑行：<br>'+ JSON.stringify(data))
            }
        });

        var $ = layui.$, active = {
            getCheckData: function(){ //获取选中数据
                var checkStatus = table.checkStatus('idTest')
                    ,data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
            ,getCheckLength: function(){ //获取选中数目
                var checkStatus = table.checkStatus('idTest')
                    ,data = checkStatus.data;
                layer.msg('选中了：'+ data.length + ' 个');
            }
            ,isAll: function(){ //验证是否全选
                var checkStatus = table.checkStatus('idTest');
                layer.msg(checkStatus.isAll ? '全选': '未全选')
            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>

</body>
</html>
